package com.slfx.function.permission.controller;


import com.slfx.function.permission.dto.MenuQueryDTO;
import com.slfx.function.permission.dto.MenuTreeListDTO;
import com.slfx.function.permission.entity.SystemMenu;
import com.slfx.function.permission.service.ISystemMenuService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author slfx
 * @since 2023-01-02
 */
@RestController
@RequestMapping("/systemMenu")
public class SystemMenuController {

    @Resource
    private ISystemMenuService systemMenuService;


    /**
     * 查询所有菜单
     *
     * @param queryParams 查询条件
     * @return 菜单列表
     */
    @ApiOperation(value = "查询所有菜单", notes = "查询所有菜单")
    @PostMapping("/list")
    public List<MenuTreeListDTO> queryMenuList(@RequestBody MenuQueryDTO queryParams) {
        List<MenuTreeListDTO> list = systemMenuService.queryMenuList(queryParams);
        return list;
    }


    /**
     * 获取菜单信息
     *
     * @param id 菜单ID
     * @return 菜单基本信息
     */
    @ApiOperation(value = "根据ID查询菜单信息")
    @GetMapping("/getById")
    public SystemMenu getMenuById(@RequestParam("id") Long id) {
        SystemMenu sysMenu = systemMenuService.getById(id);
        return sysMenu;
    }


    @ApiOperation(value = "查询当前用户权限内功能菜单")
    @GetMapping("/getUserMenu")
    public List<MenuTreeListDTO> getUserMenu(String userCode) {
        List<MenuTreeListDTO> list = systemMenuService.getUserMenu(userCode);
        return list;
    }

    /**
     * 保存菜单信息
     *
     * @param sysMenu
     * @return
     */
    @ApiOperation(value = "保存菜单信息", notes = "保存菜单信息")
    @PostMapping("/saveMenu")
    public Long saveMenu(@RequestBody @Valid SystemMenu sysMenu) {
        return systemMenuService.saveMenu(sysMenu);
    }


    /**
     * 根据ID删除菜单
     *
     * @param id 菜单ID
     * @return
     */
    @ApiOperation(value = "删除菜单")
    @ApiImplicitParam(name = "id", value = "菜单ID")
    @RequestMapping(value = "/{id}", method = {RequestMethod.GET, RequestMethod.DELETE})
    public Boolean remove(@PathVariable("id") Long id) {
        return systemMenuService.removeById(id);
    }


}
